# 	    Makefile edited by Schips
# 	    2019-06-21 schips@dingtalk.com

# 源文件路径
CSRC        = $(wildcard  *.c)
# 头文件路径
INCLUDE		= .
# 库路径
LDLIBS		= 
# 库名
LIBS 		=

# 编译选项
CFLAGS	    = -g -Wall 
CC			= gcc

# 输出文件
OUTOUT1		= s1
OUTOUT2		= s2
# 其他输入文件
OTHER_CSRC  = 
OTHER_ASRC  = 
ASRC        = 

# 调试用
INSIGHT 	= gdb
# 输出文件列表
TGT         = $(OUTOUT1) $(OUTOUT2)
########################################
# 不需要改动
INC_P  = -I 
LIBD_P = -L 
LIB_P  = -l
CFLAGS      += $(addprefix $(INC_P), $(INCLUDE)) 
LDFLAGS     += $(addprefix $(LIBD_P), $(LDLIBS)) 
LIB_ALL     += $(addprefix $(LIB_P), $(LIBS)) 
OBJS        = $(CSRC:.c=.o) $(ASRC:.S=.o)
NOLINK_OBJS = $(OTHER_CSRC:.c=.o) $(OTHER_ASRC:.S=.o)
DEPS        = $(OBJS:.o=.d) $(NOLINK_OBJS:.o=.d)
BIN         = $(TGT)
# 不需要改动
########################################

.PHONY: clean all

all: $(BIN)

debug:
	$(INSIGHT) --se=$(TGT)

# 冲突选项
OUTOUT1_OBJS := $(filter-out s2.o s3.o, $(OBJS))
OUTOUT2_OBJS := $(filter-out s1.o s3.o, $(OBJS))

#修改依赖列表以实现编译
$(OUTOUT1) : s1.o $(OUTOUT1_OBJS)
	$(CC) $(LDFLAGS) $(OUTOUT1_OBJS) $(LIB_ALL) -o $@

$(OUTOUT2) : s2.o $(OUTOUT2_OBJS)
	$(CC) $(LDFLAGS) $(OUTOUT2_OBJS) $(LIB_ALL) -o $@

#... 
#$(OUPUT3) :....


clean:
	rm -f $(DEPS)
	rm -f $(OBJS) $(NOLINK_OBJS)
	rm -f $(BIN)

# ---------------------------------------------------------------------------
# rules for code generation
# ---------------------------------------------------------------------------
%.o:    %.c
	$(CC) $(CFLAGS) -o $@ -c $<

%.o:    %.S
	$(CC) $(ASFLAGS) -o $@ -c $<

%.d: 	%.c
	@set -e; $(CC) -MM $(CFLAGS) $< \
		| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
		[ -s $@ ] || rm -f $@
-include $(DEPS)
# ---------------------------------------------------------------------------
#  # compiler generated dependencies
# ---------------------------------------------------------------------------
-include $(LWOS_DEPS) $(PORT_DEPS) $(APPL_DEPS)

